package cn.edu.zafu.bigdata.x;

import java.util.Scanner;
import java.util.Random;

public class Guess_Number {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int maxGuesses = 10; // 最大猜测次数
        int numberToGuess = random.nextInt(100) + 1; // 随机生成1到100的数字
        int guess = 0;
        int guessesTaken = 0;

        System.out.println("猜数字游戏开始！尝试猜一个1到100之间的数字。你有" + maxGuesses + "次机会。");

        while (guessesTaken < maxGuesses) {
            System.out.print("请输入你的猜测：");
            guess = scanner.nextInt();
            guessesTaken++;

            if (guess == numberToGuess) {
                System.out.println("恭喜你，猜对了！数字是" + numberToGuess);
                break;
            } else if (guess < numberToGuess) {
                System.out.println("太小了，请再试一次。");
            } else if (guess > numberToGuess) {
                System.out.println("太大了，请再试一次。");
            }

            if (guessesTaken == maxGuesses) {
                System.out.println("很遗憾，你已经用完了所有的猜测次数。数字是" + numberToGuess);
            }
        }

        scanner.close();
    }
}
